home *** CD-ROM | disk | FTP | other *** search
- /* inserti.c - insertion sort for an array of integers */
- #include "stdio.h"
-
- int insert(a,na)
- int a[] ; /* array of integers to be sorted */
- int na ; /* number of integers to be sorted */
- {
- int i , j ; /* indices for loops */
- int temp ; /* holds one element of array temporarily */
-
- for( i=1 ; i < na ; i = i + 1 )
- { /* insert the i-th element into the array */
- temp = a[i] ;
- j = i - 1 ;
- while( ( j >= 0 ) && ( temp < a[j] ) )
- { a[j+1] = a[j] ;
- j = j - 1 ;
- }
- a[j+1] = temp ;
- }
- }
-
-
-